﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DemoDestructors
{
    class Program
    {
        static void Main(string[] args)
        {
            ThirdClass theThird = new ThirdClass();
            Console.WriteLine("Objects Created ");
            Console.WriteLine("Press enter to Destroy it");
            Console.ReadLine();
            theThird = null;
            Console.Read(); 
        }
    }

    class FirstClass //: Object
    {
        /// <summary>
        /// Construtor
        /// </summary>
        public FirstClass()
        {
            Console.WriteLine("FirstClass was created.");
        }

        /// <summary>
        /// Destructor
        /// </summary>
        ~FirstClass()
        {            
            Console.WriteLine("FirstClass was destroyed.");
            //System.Diagnostics.Trace.WriteLine("First's destructor is called.");            
        }
    }

    class SecondClass : FirstClass
    {
        /// <summary>
        /// Construtor
        /// </summary>
        public SecondClass()
        {
            Console.WriteLine("SecondClass was created.");
        }

        /// <summary>
        /// Destructor
        /// </summary>
        ~SecondClass()
        {
            Console.WriteLine("SecondClass was destroyed.");
            //System.Diagnostics.Trace.WriteLine("Second's destructor is called.");
        }
    }

    class ThirdClass : SecondClass
    {
        /// <summary>
        /// Construtor
        /// </summary>
        public ThirdClass()
        {
            Console.WriteLine("ThirdClass was created.");
        }

        /// <summary>
        /// Destructor
        /// </summary>
        ~ThirdClass() 
        {
            Console.WriteLine("ThirdClass was destroyed.");
            //System.Diagnostics.Trace.WriteLine("Third's destructor is called.");
        }
    }
}
